<?php
/*
Primary Author: Derek Shue
Secondary: Alex Arey
Documentation: Cheng Yi
Updated: 12/10/2011
Module Description: The Volunteer Requests module adds/finds/updates/deletes Volunteer Requests from the database.
*/
class Application_Model_DbTable_VolunteerRequests extends Zend_Db_Table_Abstract
{

    protected $_name = 'VOLUNTEERREQUESTS';

	public function getVolunteerRequest($where)
    {
		$row = $this->fetchRow($where);
       
	   if (!$row) {
            return null;
        }
        return $row->toArray();
    }

    public function addVolunteerRequest($cpid,$positiontitle,$term,$description,$numberrequesting,$reqvehicle,$reqbgcheck,$reqheavylifting,$reqinterview,$reqspanish,$reqtbtest,$reqotherdesc,$supervisor,$time = ""){
		$vrid = $this->getNextKey();
        $data = array(
            'VRID'=> $vrid,
			'CPID'=> $cpid,
			'POSITIONTITLE'=> $positiontitle,
			'TERM'=> $term,
			'DESCRIPTION'=> $description,
			'NUMBERREQUESTING'=> $numberrequesting,
			'REQVEHICLE'=> $reqvehicle,
			'REQBGCHECK'=> $reqbgcheck,
			'REQHEAVYLIFTING'=> $reqheavylifting,
			'REQINTERVIEW'=> $reqinterview,
			'REQSPANISH'=> $reqspanish,
			'REQTBTEST'=> $reqtbtest,
			'REQOTHERDESC'=> $reqotherdesc,
			'SUPERVISOR'=>$supervisor,
			'TIME'=> $time,
        );
		$this->insert($data);
		return $vrid;
    }

    public function updateVolunteerRequest($vrid,$cpid,$positiontitle,$term,$description,$numberrequesting,$reqvehicle,$reqbgcheck,$reqheavylifting,$reqinterview,$supervisor,$reqspanish,$reqtbtest,$reqotherdesc,$time
)
    {
        $data = array(
        'VRID'=>$vrid,
		'CPID'=> $cpid,
		'POSITIONTITLE'=> $positiontitle,
		'TERM'=> $term,
		'DESCRIPTION'=> $description,
		'NUMBERREQUESTING'=> $numberrequesting,
		'REQVEHICLE'=> $reqvehicle,
		'REQBGCHECK'=> $reqbgcheck,
		'REQHEAVYLIFTING'=> $reqheavylifting,
		'REQINTERVIEW'=> $reqinterview,
		'REQSPANISH'=> $reqspanish,
		'REQTBTEST'=> $reqtbtest,
		'REQOTHERDESC'=> $reqotherdesc,
        'SUPERVISOR'=>$supervisor,
		'TIME'=> $time,
        );
		print_r($data);
        $this->update($data, 'VRID = '. (int)$vrid);
    }

    public function deleteVolunteerRequest($where)
    {
        $this->delete($where);
    }

	public function getNextKey(){
		$sqlquery = $this->select()->from($this->_name, array("MAX(VRID)"));
		$insertrow = $this->fetchRow($sqlquery)->toArray(); 
		return $insertrow["MAX(VRID)"] + 1;
	}

}












































































































